#region License Revision: 0 Last Revised: 6/18/2008 11:00 AM
/******************************************************************************
Copyright (c) Microsoft Corporation.  All rights reserved.


This file is licensed under the Microsoft Public License (Ms-PL). A copy of the Ms-PL should accompany this file. 
If it does not, you can obtain a copy from: 

http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx
******************************************************************************/
#endregion // License
using System;
using System.Windows.Browser;
using System.Diagnostics;
using System.Windows.Media;
using ScriptInterop;


namespace VIEWS // Virtual Earth Wrapper
{

	/// <summary>Wrapper class for the VEColor object.</summary>
	public class VEColor : JSObject
	{
		/// <summary>String holding JavaScript class name</summary>
		private static string thisClass = "VEColor";
		
		/// <summary>Get the JavaScript class name</summary>
		/// <returns type="String">The class name used in JavaScript </returns>		
		public override string ClassName
		{
			get { return thisClass; }
		}

		/// <summary>Construct a C# wrapper from a ScriptObject</summary>
		public VEColor(ScriptObject so) : base(so) { }

		/// <summary>Initializes a new instance of the VEColor object.</summary>
		/// <param name="r" type="Number">The red component value. Valid values range from 0 through 255.</param>
		/// <param name="g" type="Number">The green component value. Valid values range from 0 through 255.</param>
		/// <param name="b" type="Number">The blue component value. Valid values range from 0 through 255.</param>
		/// <param name="a" type="Number">The alpha (transparency) component value. Valid values range from 0.0 through 1.0.</param>
		public VEColor(int r, int g, int b, double a)
		{	
			ScriptObject = CreateClass(r,g,b,a);
		}

		/// <summary>
		/// Construct a color obect from a Managed type
		/// </summary>
		/// <param name="color">Managed color type to match</param>
		public VEColor(Color color)
		{
			ScriptObject = CreateClass((int)color.R, (int)color.G, (int)color.B, (double)color.A/255);
		}

		public static explicit operator Color(VEColor color)
		{
			Color clr = new Color();
			clr.R = (byte)color.R;
			clr.G = (byte)color.G;
			clr.B = (byte)color.B;
			clr.A = (byte)(color.A*255);
			return clr;
		}

        /// <summary>
        /// Converts a <see cref="VEColor"/> to a <see cref="Color"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="Color"/> that represents the <see cref="VEColor"/>.
        /// </returns>
        public Color ToColor()
        {
            return (Color)this;
        }

		/// <summary>
		/// The red component value. Valid values range from 0 through 255.
		/// </summary>
		public int R
		{
			get { return GetProperty<int>("R"); }
			set { SetProperty("R", value); }
		}
		/// <summary>
		/// Green value. Valid values range from 0 through 255
		/// </summary>
		public int G
		{
			get { return GetProperty<int>("G"); }
			set { SetProperty("G", value); }
		}
		/// <summary>
		/// Blue Value. Valid values range from 0 through 255
		/// </summary>
		public int B
		{
			get { return GetProperty<int>("B"); }
			set { SetProperty("B", value); }
		}
		/// <summary>
		/// Alpha value (Transparency). Valid values range from 0.0 through 1.0
		/// </summary>
		public double A
		{
			get { return GetProperty<double>("A"); }
			set { SetProperty("A", value); }
		}
	}

}
